home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-02 / bgisnap1.zip / BGISNAP.C < prev    next >
C/C++ Source or Header  |  1992-01-19  |  4KB  |  86 lines

  1. /**╟─────────────────────────────────────────────────────╢
  2.  **║                                                     ║
  3.  **║      Copyright MCMXCI, Jeffrey Chasen                ║
  4.  **║      Copyright MCMXCII, Jeffrey Chasen               ║     
  5.  **║                                                     ║
  6.  **║                                                                    ║
  7.  **╟─────────────────────────────────────────────────────╢
  8. */
  9.  
  10. #include <stdlib.h>
  11. #include <stdio.h>
  12. #include <fcntl.h>
  13. #include <sys\stat.h>
  14. #include <dos.h>
  15. #include <conio.h>
  16. #include <alloc.h>
  17. #include <graphics.h>
  18.  
  19. /* -------------------------------------------------------------------  */
  20. /* The file created by BGISNap contains a header telling how many image */
  21. /* segments the image was split in to.  Borland BGI has a max size of   */
  22. /* 64K for any given image.                                             */
  23. /*                                                                      */
  24. /* Format of the file created by BGISnap is as follows:                 */
  25. /*     Header  -- (contains 2 bytes which is the number of segments)    */
  26. /*     Byte 1  -- (int) containing the number of image segments         */
  27. /*     Byte 2  -- contained in this file (a segment can be up to 64k)   */
  28. /*                                                                      */
  29. /*     Segment 1 (all byte positions are now relative to this segment)  */
  30. /*     Byte 1 -- (unsigned int) containing the byte size of this segment*/
  31. /*     Byte 2                                                           */
  32. /*                                                                      */
  33. /*     Byte 3 -- (int) containg the X position of the image             */
  34. /*     Byte 4                                                           */
  35. /*                                                                      */
  36. /*     Byte 5 -- (int) containg the Y position of the segment           */
  37. /*     Byte 6                                                           */
  38. /*                                                                      */
  39. /*     Byte 7 -- Beginning of image data (a normal putimage() can be    */
  40. /*               done on his data)                                      */
  41. /*     .............                                                    */
  42. /*     Segment 2 .etc                                                   */
  43. /* -------------------------------------------------------------------  */
  44.  
  45. /* -------------------------------------------------------------------  */
  46. /* This function will display an image snapped by BGISnap into file     */
  47. /* The graphics system must have been previously been initialized       */
  48. /* to the proper mode.                                                  */
  49. /* -------------------------------------------------------------------  */
  50. void displayBGIImage(char *file)
  51. {
  52.     int i, x1, y1, numSegments;
  53.     static char far *buf = NULL;
  54.     unsigned int gSeg, size;    
  55.     FILE *fp;
  56.     
  57.     fp = fopen(file,"rb");
  58.     if (fp == NULL)
  59.         return;
  60.     
  61.     // allocate memory first time from DOS
  62.     // can be changed to allocate each time the function is called
  63.     // or even for each segment
  64.     if (buf == NULL)
  65.     {
  66.         unsigned int size = 64*(1024/16);        // allocate 64K which is
  67.         allocmem(size,&gSeg);                  // the largest a segment can be
  68.         buf = (char far *)MK_FP(gSeg,0);        
  69.     }
  70.         
  71.     
  72.     fread(&numSegments,1,sizeof(int),fp); // read each segment and
  73.     for (i = 0; i < numSegments; i++)     // display it at the proper position
  74.     {
  75.         fread(&size,1,sizeof(int),fp);        
  76.         fread(&x1,1,sizeof(int),fp);
  77.         fread(&y1,1,sizeof(int),fp);
  78.         fread(buf,1,size,fp);
  79.         putimage(x1,y1,buf,COPY_PUT);
  80.     }
  81.     
  82. /*    freemem(gSeg); can be used to free memory each time if it is needed */
  83.     
  84.     fclose(fp);
  85. }
  86.